<?php

namespace App\Admin\Controllers\SysManage;

use App\Http\Controllers\Controller;

use App\Models\SysParams;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Row;
use Illuminate\Http\Request;
use Encore\Admin\Controllers\ModelForm;

class SysParamsController
{
    use ModelForm;
    //用户列表
    public function index()
    {
        return Admin::content(function(Content $content){
            $content->header( '全域设置');
            //$content->description('列表');
            $content->body($this->grid()->render());

        });
    }
    public function edit($id) {
        return Admin::content(function (Content $content) use ($id) {
            $content->body($this->form()->edit($id));
        });
    }

    protected function grid(){
        return Admin::grid(SysParams::class,function(Grid $grid){
            $grid->model()->where('title',"!=", '');
            $grid->id('编号')->sortable();

//            $grid->name('名称');
//            var_dump($this->row);exit;
            $grid->title('名称');

            $grid->value('值');

            $grid->actions(function ($actions) {
                if ($actions->row['isedit'] == 0) {
                    $actions->disableEdit();
                }

                $actions->disableDelete();
            });

            $grid->disableExport();
            $grid->disableCreation();
            $grid->disableRowSelector();

        });
    }

    protected function form()
    {
        return Admin::form(SysParams::class, function (Form $form) {
            $form->display('id', '编号');
            $form->display('title', '名称');
            $form->text('value', '值');

        });
    }

}
